﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using FbKPI.Facade;
using FbKPI.Model;
using System.Web.Security;

namespace FBKPI
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        protected void Page_Init(object sender, EventArgs e)
        {

            if (Context.Session["UserLoggedIn"] != null)
            {
                //DefineUser(Context.Session["UserLoggedIn"].ToString());

                int UserID = Convert.ToInt32(Context.Session["UserLoggedIn"]);
                Employee obj = new EmployeeFacade().GetEmployeeByID(UserID);
                if (obj != null)
                {
                    //lblBussinesGroup.Text = obj.BusinessGroupID.ToString();
                    BusinessGroup objBusiness = new BusinessGroupFacade().GetBusinessGroupByID(obj.BusinessGroupID);
                    //if (objBusiness != null)
                    //    lblBussinesGroup.Text = objBusiness.Description;

                    SetupYearFacade fy = new SetupYearFacade();
                    SetupYear objYear = fy.GetByID(1);
                    //lblKpiYear.Text = "KPI Year : " + objYear.EndYear.ToString();// +" - " + objYear.EndYear.ToString();

                    txt_user.Value = UserID.ToString();
                    Employee emp = new EmployeeFacade().GetEmployeeByID(Convert.ToInt32(txt_user.Value));
                    lblUser.Text = emp.FirstName + " " + emp.LastName;
                }
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "PopupScript", "<script type=text/javascript> clearCookiesTree(); </script>", true);

                FormsAuthentication.SignOut();
                Session.Abandon();

                HttpCookie aCookie;
                string cookieName;
                int limit = Request.Cookies.Count;
                for (int i = 0; i < limit; i++)
                {
                    cookieName = Request.Cookies[i].Name;
                    aCookie = new HttpCookie(cookieName);
                    aCookie.Expires = DateTime.Now.AddDays(-1);
                    Response.Cookies.Add(aCookie);
                }
                Response.Redirect(FormsAuthentication.LoginUrl, false);

            }

        }

    }
}

